package com.ruoyi.web.controller.app;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.plugin.excel.annotation.RequestExcel;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.vo.coopHan.*;
import com.ruoyi.system.dto.coopHan.*;
import com.ruoyi.system.service.IAssociationClapCulvertService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.rmi.ServerException;
import java.util.List;

/**
 * <p>
 * 协拍涵表 前端控制器
 * </p>
 *
 * @author yanfu
 * @since 2024-03-01
 */
@RestController
@RequestMapping("/app/association/clap/culvert")
@RequiredArgsConstructor
@Api(tags = {"(app)协拍涵API"})
public class AppAssociationClapCulvertController extends BaseController {

    private final IAssociationClapCulvertService associationClapCulvertService;


    @PostMapping("/save")
    @ApiOperation(value = "协拍涵添加草稿---手机端 ")
    public AjaxResult<Long> saveCulvert(@RequestBody CulvertDto dto) {
        Long id = associationClapCulvertService.saveCulvert(dto);
        return AjaxResult.success(id);
    }


    @PostMapping("/saveAndCommit")
    @ApiOperation(value = "协拍涵保存并提交---手机端 描述：如果调用了/save方法需要带上返回的id 如果没有调用直接调用此方法")
    public AjaxResult<String> saveAndCommit(@RequestBody CulvertDto dto) throws Exception {
        String flowId = associationClapCulvertService.saveAndCommit(dto);
        return AjaxResult.success(flowId);
    }

    @GetMapping("/detail")
    @ApiOperation(value = "协拍涵详情---手机端")
    public AjaxResult<CulvertDetailVo> detailCulvert(@RequestParam Long id) throws ServerException {
        CulvertDetailVo vo = associationClapCulvertService.detailCulvert(id);
        return AjaxResult.success(vo);
    }

    @DeleteMapping("/del")
    @ApiOperation(value = "协拍涵删除---手机端")
    public AjaxResult<String> delCulvert(@RequestParam Long id) throws ServerException {
        associationClapCulvertService.delCulvert(id);
        return AjaxResult.success("协拍涵删除成功");
    }

    @PutMapping("/update")
    @ApiOperation(value = "协拍涵草稿编辑---手机端")
    public AjaxResult<String> putCulvert(@RequestBody CulvertDto dto) throws Exception {
        associationClapCulvertService.putCulvert(dto);
        return AjaxResult.success("协拍涵草稿编辑成功");
    }

    @PostMapping("/notice/page")
    @ApiOperation(value = "协拍涵公示列表")
    public AjaxResult<Page<PageCulvertNoticeVo>> pagePublicityCulvert(@RequestBody PageCulvertNoticeDto dto) {
        Page<PageCulvertNoticeVo> page = associationClapCulvertService.pagePublicityCulvert(dto);
        return AjaxResult.success(page);
    }

    @GetMapping("/notice/detail")
    @ApiOperation(value = "协拍涵公示详情")
    public AjaxResult<CulvertNoticeDetailVo> noticeDetail(@ApiParam(value = "协拍涵ID", required = true)
                                                              @RequestParam Long id) {
        CulvertNoticeDetailVo vo = associationClapCulvertService.noticeDetail(id);
        return AjaxResult.success(vo);
    }


    @PostMapping("/import")
    @ApiOperation(value = "协拍涵-场景数据excel导入-返回列表")
    public  AjaxResult<List<CulvertExcelVo>> importCert(@RequestPart("file") MultipartFile file, HttpServletRequest request) throws Exception {
        List<CulvertExcelVo> vos=  associationClapCulvertService.importCert(file,request);
        return AjaxResult.success(vos);
    }
}

